cssvalue: Add a css value for engines
authorBenjamin Otte <otte@redhat.com>
Tue, 3 Apr 2012 19:26:34 +0000 (21:26 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 17 Apr 2012 06:59:18 +0000 (08:59 +0200)
gtk/Makefile.am
gtk/gtkcssenginevalue.c [new file with mode: 0644]
gtk/gtkcssenginevalueprivate.h [new file with mode: 0644]
gtk/gtkcssstylepropertyimpl.c
gtk/gtkcssvalue.c
gtk/gtkcssvalueprivate.h

index 3d7dd85f07f34d53ed57c19da5b6247db52d8584..14163200426288fc31c00c9ee594702d40261fa3 100644 (file)
@@ -428,6 +428,7 @@ gtk_private_h_sources =             \
        gtkcsscornervalueprivate.h      \
        gtkcsscustompropertyprivate.h \
        gtkcsseasevalueprivate.h        \
+       gtkcssenginevalueprivate.h      \
        gtkcssenumvalueprivate.h        \
        gtkcssimagecrossfadeprivate.h   \
        gtkcssimagegradientprivate.h    \
@@ -638,6 +639,7 @@ gtk_base_c_sources =                \
        gtkcsscustomproperty.c  \
        gtkcsseasevalue.c       \
        gtkcssenumvalue.c       \
+       gtkcssenginevalue.c     \
        gtkcssimage.c           \
        gtkcssimagecrossfade.c  \
        gtkcssimagegradient.c   \
diff --git a/gtk/gtkcssenginevalue.c b/gtk/gtkcssenginevalue.c
new file mode 100644 (file)
index 0000000..ff4ba67
--- /dev/null
@@ -0,0 +1,127 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtkcssenginevalueprivate.h"
+
+#include "gtkstylepropertyprivate.h"
+
+struct _GtkCssValue {
+  GTK_CSS_VALUE_BASE
+  GtkThemingEngine *engine;
+};
+
+static void
+gtk_css_value_engine_free (GtkCssValue *value)
+{
+  g_object_unref (value->engine);
+
+  g_slice_free (GtkCssValue, value);
+}
+
+static gboolean
+gtk_css_value_engine_equal (const GtkCssValue *value1,
+                            const GtkCssValue *value2)
+{
+  return value1->engine == value2->engine;
+}
+
+static GtkCssValue *
+gtk_css_value_engine_transition (GtkCssValue *start,
+                                 GtkCssValue *end,
+                                 double       progress)
+{
+  return NULL;
+}
+
+static void
+gtk_css_value_engine_print (const GtkCssValue *value,
+                            GString           *string)
+{
+  char *name;
+
+  g_object_get (value->engine, "name", &name, NULL);
+
+  if (name)
+    g_string_append (string, name);
+  else
+    g_string_append (string, "none");
+
+  g_free (name);
+}
+
+static const GtkCssValueClass GTK_CSS_VALUE_ENGINE = {
+  gtk_css_value_engine_free,
+  gtk_css_value_engine_equal,
+  gtk_css_value_engine_transition,
+  gtk_css_value_engine_print
+};
+
+GtkCssValue *
+_gtk_css_engine_value_new (GtkThemingEngine *engine)
+{
+  GtkCssValue *result;
+
+  g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
+
+  result = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_ENGINE);
+  result->engine = g_object_ref (engine);
+
+  return result;
+}
+
+GtkCssValue *
+_gtk_css_engine_value_parse (GtkCssParser *parser)
+{
+  GtkThemingEngine *engine;
+  char *str;
+
+  g_return_val_if_fail (parser != NULL, NULL);
+
+  if (_gtk_css_parser_try (parser, "none", TRUE))
+    return _gtk_css_engine_value_new (gtk_theming_engine_load (NULL));
+
+  str = _gtk_css_parser_try_ident (parser, TRUE);
+  if (str == NULL)
+    {
+      _gtk_css_parser_error (parser, "Expected a valid theme name");
+      return NULL;
+    }
+
+  engine = gtk_theming_engine_load (str);
+
+  if (engine == NULL)
+    {
+      _gtk_css_parser_error (parser, "Theming engine '%s' not found", str);
+      g_free (str);
+      return NULL;
+    }
+
+  g_free (str);
+
+  return _gtk_css_engine_value_new (engine);
+}
+
+GtkThemingEngine *
+_gtk_css_engine_value_get_engine (const GtkCssValue *value)
+{
+  g_return_val_if_fail (value->class == &GTK_CSS_VALUE_ENGINE, NULL);
+
+  return value->engine;
+}
+
diff --git a/gtk/gtkcssenginevalueprivate.h b/gtk/gtkcssenginevalueprivate.h
new file mode 100644 (file)
index 0000000..888c07a
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright © 2012 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Alexander Larsson <alexl@gnome.org>
+ */
+
+#ifndef __GTK_CSS_ENGINE_VALUE_PRIVATE_H__
+#define __GTK_CSS_ENGINE_VALUE_PRIVATE_H__
+
+#include "gtkcssparserprivate.h"
+#include "gtkcssvalueprivate.h"
+#include "gtkthemingengine.h"
+
+G_BEGIN_DECLS
+
+GtkCssValue *       _gtk_css_engine_value_new           (GtkThemingEngine       *engine);
+GtkCssValue *       _gtk_css_engine_value_parse         (GtkCssParser           *parser);
+
+GtkThemingEngine *  _gtk_css_engine_value_get_engine    (const GtkCssValue      *engine);
+
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_ENGINE_VALUE_PRIVATE_H__ */
index 6e645a7e91c78cbefd726e5a8f6ad0c65800fb04..cfae447415622d429a4b668f4aeab914168dee15 100644 (file)
@@ -43,6 +43,7 @@
 #include "gtkcssarrayvalueprivate.h"
 #include "gtkcsscornervalueprivate.h"
 #include "gtkcsseasevalueprivate.h"
+#include "gtkcssenginevalueprivate.h"
 #include "gtkcssimagegradientprivate.h"
 #include "gtkcssimageprivate.h"
 #include "gtkcssimagevalueprivate.h"
@@ -772,31 +773,23 @@ engine_parse (GtkCssStyleProperty *property,
               GtkCssParser        *parser,
               GFile               *base)
 {
-  GtkThemingEngine *engine;
-  char *str;
-
-  if (_gtk_css_parser_try (parser, "none", TRUE))
-    return _gtk_css_value_new_from_theming_engine (gtk_theming_engine_load (NULL));
-
-  str = _gtk_css_parser_try_ident (parser, TRUE);
-  if (str == NULL)
-    {
-      _gtk_css_parser_error (parser, "Expected a valid theme name");
-      return NULL;
-    }
-
-  engine = gtk_theming_engine_load (str);
-
-  if (engine == NULL)
-    {
-      _gtk_css_parser_error (parser, "Theming engine '%s' not found", str);
-      g_free (str);
-      return NULL;
-    }
+  return _gtk_css_engine_value_parse (parser);
+}
 
-  g_free (str);
+static void
+engine_query (GtkCssStyleProperty *property,
+              const GtkCssValue   *css_value,
+              GValue              *value)
+{
+  g_value_init (value, GTK_TYPE_THEMING_ENGINE);
+  g_value_set_object (value, _gtk_css_engine_value_get_engine (css_value));
+}
 
-  return _gtk_css_value_new_from_theming_engine (engine);
+static GtkCssValue *
+engine_assign (GtkCssStyleProperty *property,
+               const GValue        *value)
+{
+  return _gtk_css_engine_value_new (g_value_get_object (value));
 }
 
 static GtkCssValue *
@@ -1857,10 +1850,10 @@ _gtk_css_style_property_init_properties (void)
                                           engine_parse,
                                           NULL,
                                           NULL,
-                                          query_simple,
-                                          assign_simple,
+                                          engine_query,
+                                          engine_assign,
                                           NULL,
-                                          _gtk_css_value_new_from_theming_engine (gtk_theming_engine_load (NULL)));
+                                          _gtk_css_engine_value_new (gtk_theming_engine_load (NULL)));
   gtk_css_style_property_register        ("transition",
                                           GTK_CSS_PROPERTY_TRANSITION,
                                           GTK_TYPE_ANIMATION_DESCRIPTION,
index f2fd69a36da565d42464cc04fadc06b0e327f7b2..83b79a183b45d9f57d3541f36337a44cdd18945d 100644 (file)
@@ -256,17 +256,6 @@ _gtk_css_value_new_take_pattern (cairo_pattern_t *v)
   return value;
 }
 
-GtkCssValue *
-_gtk_css_value_new_from_theming_engine (GtkThemingEngine *v)
-{
-  GtkCssValue *value;
-
-  value = gtk_css_value_new (GTK_TYPE_THEMING_ENGINE);
-  value->u.ptr = g_object_ref (v);
-
-  return value;
-}
-
 GtkCssValue *
 _gtk_css_value_new_take_binding_sets (GPtrArray *array)
 {
index aacc230139f2ce6f8c1281e0d3eb958c0441f36b..6541cf2174074bf8f280031dfd32b1ce60c3b96c 100644 (file)
@@ -23,7 +23,6 @@
 #include <glib-object.h>
 #include "gtkcsstypesprivate.h"
 #include "gtksymboliccolor.h"
-#include "gtkthemingengine.h"
 
 G_BEGIN_DECLS
 
@@ -88,7 +87,6 @@ GtkCssValue *_gtk_css_value_new_from_boxed            (GType
 GtkCssValue *_gtk_css_value_new_from_color            (const GdkColor             *v);
 GtkCssValue *_gtk_css_value_new_take_symbolic_color   (GtkSymbolicColor           *v);
 GtkCssValue *_gtk_css_value_new_take_pattern          (cairo_pattern_t            *v);
-GtkCssValue *_gtk_css_value_new_from_theming_engine   (GtkThemingEngine           *v);
 GtkCssValue *_gtk_css_value_new_take_binding_sets     (GPtrArray                  *array);
 GtkCssValue *_gtk_css_value_new_from_background_size  (const GtkCssBackgroundSize *v);
 GtkCssValue *_gtk_css_value_new_from_background_position (const GtkCssBackgroundPosition *v);